package com.seguriapp.common.gwt.client;

import java.util.HashMap;
import java.util.Map;

public class SeguriAppClientSession {

  public enum Key {
    Alert, Complaint, isNewUser, User, NoUserMenus
  }

  private static final SeguriAppClientSession INSTANCE = new SeguriAppClientSession();

  private Map<Key, Object> sessionInformation;
  private Map<Key, Boolean> persistence;

  /**
   * Singleton class constructor.
   */
  private SeguriAppClientSession() {
    sessionInformation = new HashMap<SeguriAppClientSession.Key, Object>();
    persistence = new HashMap<SeguriAppClientSession.Key, Boolean>();
  }

  public void put(final Key key, final Object value) {
    put(key, value, false);
  }

  public void put(final Key key, final Object value, final boolean persistent) {
    sessionInformation.put(key, value);
    persistence.put(key, persistent);
  }

  public Object get(final Key key) {
    final Object obj = sessionInformation.get(key);
    if (obj == null) {
      return null;
    }
    if (!persistence.get(key)) {
      remove(key);
    }
    return obj;
  }

  public void remove(final Key key) {
    sessionInformation.remove(key);
    persistence.remove(key);
  }

  public static final SeguriAppClientSession get() {
    return INSTANCE;
  }

}
